package cn.iocoder.yudao.module.system.controller.admin.queryscene;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.system.controller.admin.queryscene.vo.*;
import cn.iocoder.yudao.module.system.dal.dataobject.queryscene.QuerySceneDO;
import cn.iocoder.yudao.module.system.service.queryscene.QuerySceneService;

@Tag(name = "管理后台 - 高级查询场景")
@RestController
@RequestMapping("/system/query-scene")
@Validated
public class QuerySceneController {

    @Resource
    private QuerySceneService querySceneService;

    @PostMapping("/create")
    @Operation(summary = "创建高级查询场景")
    public CommonResult<Long> createQueryScene(@Valid @RequestBody QuerySceneSaveReqVO createReqVO) {
        return success(querySceneService.createQueryScene(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新高级查询场景")
    public CommonResult<Boolean> updateQueryScene(@Valid @RequestBody QuerySceneSaveReqVO updateReqVO) {
        querySceneService.updateQueryScene(updateReqVO);
        return success(true);
    }


    @DeleteMapping("/delete")
    @Operation(summary = "删除高级查询场景")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteQueryScene(@RequestParam("id") Long id) {
        querySceneService.deleteQueryScene(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得高级查询场景")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<QuerySceneRespVO> getQueryScene(@RequestParam("id") Long id) {
        QuerySceneDO queryScene = querySceneService.getQueryScene(id);
        return success(BeanUtils.toBean(queryScene, QuerySceneRespVO.class));
    }


    @GetMapping("/list")
    @Operation(summary = "获取场景列表")
    public CommonResult<List<QuerySceneRespVO>> getQueryScene(@RequestParam("page") String page) {
        List<QuerySceneDO> queryScene = querySceneService.getQuerySceneListByPage(page);
        return success(BeanUtils.toBean(queryScene, QuerySceneRespVO.class));
    }


    @GetMapping("/page")
    @Operation(summary = "获得高级查询场景分页")
    public CommonResult<PageResult<QuerySceneRespVO>> getQueryScenePage(@Valid QueryScenePageReqVO pageReqVO) {
        PageResult<QuerySceneDO> pageResult = querySceneService.getQueryScenePage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, QuerySceneRespVO.class));
    }


    @GetMapping("/get-conditions")
    @Operation(summary = "获得高级查询场景分页")
    @Parameter(name = "page", description = "编号", required = true, example = "1024")
    public CommonResult<List<QuerySceneBaseVO>> getConditions(@RequestParam("page") String page) {
        List<QuerySceneBaseVO> pageResult = querySceneService.getConditions(page);
        return success(pageResult);
    }

}